import { identity, pickBy, isNumber, isEmpty } from 'lodash';
import request from '@/http/request';
import { IQueryParams } from '@/widgets/table-pagination';
import Qs from 'qs';

export function getList(queryParams: IQueryParams) {
  let filterParam: any = {
    ...queryParams,
    ...pickBy(queryParams.filter, (value) => {
      return !isEmpty(value);
    }),
    ...pickBy(queryParams.filter, isNumber),
  };
  filterParam.page = filterParam.pageNum - 1;
  filterParam.size = filterParam.pageSize;
  delete filterParam.filter;
  delete filterParam.pageNum;
  delete filterParam.pageSize;

  const param = Qs.stringify(filterParam);
  return request.get(`/opportunity/getPage?${param}`);
}

export function createItem(entity: any) {
  return request.post(`/admin-api/system/org/create`, entity);
}

export function updateItem(entity: any) {
  return request.put(`/admin-api/system/org/update`, entity);
}

export function deleteItem(key: any) {
  return request.delete(`/admin-api/system/org/delete?id=${key}`);
}

export function getCount() {
  return request.get(`/opportunity/count`);
}
